package cn.jbolt.common.base;

import com.alibaba.fastjson.JSONObject;

/**
 * 通用请求消息体，主要是为了通过校验请求参数是否合法
 */
public class BaseReqMsg extends JSONObject {

    public boolean getSuccess() {
        return this.getBoolean("success");
    }

    public void setSuccess(boolean success) {
        this.put("success",success);
    }

    public String getErrorMsg() {
        return this.getString("errorMsg");
    }

    public void setErrorMsg(String errorMsg) {
        this.put("errorMsg",errorMsg);
    }

    public void validate(String... params){
        this.setSuccess(true);
        for(String key:params){
            if(this.containsKey(key)){
                if(null==this.get(key)||this.get(key).equals("")){
                    this.setSuccess(false);
                    this.setErrorMsg("参数"+key+"不能为空值！");
                    return;
                }
            }else{
                this.setSuccess(false);
                this.setErrorMsg("缺少参数"+key+"!");
                return;
            }
        }
    }
}

